package com.health.common;

import lombok.Data;

import static com.health.common.ResultCode.ERROR;
import static com.health.common.ResultCode.SUCCESS;


/**
 * @Description
 * @Author konglz
 * @Data 2023/2/28 16:08
 */
@Data
public class Result<T>{
    private Integer code;

    private String message;

    private T data;

    Result(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static Result sucess() {
        return new Result(SUCCESS.getCode(), SUCCESS.getMessage(), null);
    }

    public static Result sucess(Object data) {
        return new Result(SUCCESS.getCode(), SUCCESS.getMessage(), data);
    }

    public static Result success(int code, String message) {
        return new Result(code, message, null);
    }

    public static Result success(String message) {
        return new Result(SUCCESS.getCode(), message, null);
    }

    public static Result success(int code, String message, Object data) {
        return new Result(code, message, data);
    }

    public static Result error(Object data) {
        return new Result(ERROR.getCode(), ERROR.getMessage(), data);
    }


    public static Result error(int code, String message) {
        return new Result(code, message, null);
    }

    public static Result error(String message) {
        return new Result(ERROR.getCode(), message, null);
    }

    public static Result error(int code, String message, Object data) {
        return new Result(code, message, data);
    }
}
